#ifndef RICHTERDATABASE_H
#define RICHTERDATABASE_H

#include <mysql/mysql.h>
#include <vector>
#include "datatypes.h"
#include "sha1.h"

class RichterDatabase
{
public:
    static RichterDatabase &instance();

    void connect(const char * server, const char * user, const char * password);

    ~RichterDatabase();


    /////////////////////////
    // Places
    /////////////////////////

    void addPlace(const char * name);
    vector<Places> getPlaces();
    void removePlace(int id);

    /////////////////////////
    // Users
    /////////////////////////

    void addUser(const char * name,
                 const char * password);
    void changePassword(const char * oldPassword,
                        const char * newPassword);
    bool checkUser(const char * name,
                   const char * password);
    vector<Users> getUsers();
    void removeUser(int id);


private:

    struct TableData {
        const char * m_name;
        const char * m_createCommand;
    };

    RichterDatabase();

    RichterDatabase(const RichterDatabase & eredeti);

    MYSQL * m_connect;

    bool checkDatabaseExists();

    void query(const char * command) const;

    void fixTables();

    bool tableExists(const char * name) const;

    void insertInto(char * tableName, unsigned int count, ...);
};

#endif // RICHTERDATABASE_H
